<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var partitionLabels = function (s) {
      const last = new Array(26);
      const length = s.length;
      const codePointA = 'a'.codePointAt(0);
      for (let i = 0; i < length; i++) {
        last[s.codePointAt(i) - codePointA] = i;
      }
      const partition = [];
      let start = 0, end = 0;
      for (let i = 0; i < length; i++) {
        end = Math.max(end, last[s.codePointAt(i) - codePointA]);
        if (i == end) {
          partition.push(end - start + 1);
          start = end + 1;
        }
      }
      return partition;
    };
    console.log(partitionLabels("ababcbacadefegdehijhklij"))
  </script>
</body>

</html>